home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWRefCnt / Include / FWSOMPtr.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  2.6 KB  |  104 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSOMPtr.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSOMPTR_H
  11. #define FWSOMPTR_H
  12.  
  13. #ifndef FWEXCLIB_H
  14. #include "FWExcLib.h"
  15. #endif
  16.  
  17. //========================================================================================
  18. // TSOMPtr
  19. //    This class encapsulates an auto-destructing pointer to a SOM object.  This is 
  20. //    presumed to be the only pointer to that SOM object; assignment of another TRep*
  21. //    deletes the current one.
  22. //========================================================================================
  23.  
  24. template<class TRep>
  25. class FW_TSOMPtr
  26. {
  27. public:
  28.     FW_DECLARE_AUTO(FW_TSOMPtr<TRep>)
  29.                         ~FW_TSOMPtr();            // dtors of auto objects must be public
  30.  
  31. protected:
  32.                         FW_TSOMPtr();
  33.                         FW_TSOMPtr(Environment *ev, TRep* rep);
  34.  
  35. public:
  36.     TRep*                 operator->() const
  37.                             { return fRep; }
  38.  
  39.     operator             TRep*() const
  40.                             { return fRep; }
  41.  
  42.     TRep*                 GetRep() const
  43.                             { return fRep; }
  44.  
  45.     void                SetRep(Environment *ev, TRep* rep);
  46.  
  47. private:    
  48.     TRep*                fRep;
  49.  
  50. private:
  51.     // There are no copy constructors or assignment operators allowed.
  52.                         FW_TSOMPtr(const FW_TSOMPtr<TRep>& other);
  53.     void                operator=(const FW_TSOMPtr<TRep>& other);
  54. };
  55.  
  56.  
  57.  
  58. //========================================================================================
  59. // FW_TCountedSOMPtr
  60. //    This class encapsulates a counted pointer to a SOM object.
  61. //========================================================================================
  62.  
  63. template<class TRep>
  64. class FW_TCountedSOMPtr
  65. {
  66. public:
  67.     FW_DECLARE_AUTO(FW_TCountedSOMPtr<TRep>)
  68.                         ~FW_TCountedSOMPtr();    // dtors of auto objects must be public
  69.  
  70. protected:
  71.                         FW_TCountedSOMPtr();
  72.  
  73.                         FW_TCountedSOMPtr(const FW_TCountedSOMPtr<TRep>& other);
  74.                         FW_TCountedSOMPtr(Environment *ev, const FW_TCountedSOMPtr<TRep>& other);
  75.     void                operator=(const FW_TCountedSOMPtr<TRep>& other)
  76.                             { operator=(other.fRep); }
  77.  
  78.                         FW_TCountedSOMPtr(Environment *ev, TRep* other);
  79.     void                operator=(TRep* other);
  80.  
  81. public:
  82.     FW_Boolean            IsSameRepAs(const FW_TCountedSOMPtr<TRep>& other) const
  83.                             { return IsSameRepAs(other.fRep); }
  84.  
  85.     FW_Boolean            IsSameRepAs(const TRep* other) const
  86.                             { return fRep == other; }
  87.  
  88.     TRep*                 operator->() const
  89.                             { return fRep; }
  90.  
  91.     operator             TRep*() const
  92.                             { return fRep; }
  93.  
  94.     TRep*                 GetRep() const
  95.                             { return fRep; }
  96.  
  97.     void                SetRep(Environment *ev, TRep* rep);
  98.  
  99. private:    
  100.     TRep*                fRep;
  101. };
  102.  
  103. #endif
  104.